﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using HoneyBadgersOfficePlayer.Models;

namespace HoneyBadgersOfficePlayer.Views
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
            ChangePasswordHyperLink.NavigateUrl = "ChangePassword.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);

        }

        protected void Button_Click(object sender, EventArgs e)
        {
            List<SqlParameter> parameterList = new List<SqlParameter>();
            parameterList.Add(new SqlParameter("@Login", LoginUser.UserName));
            parameterList.Add(new SqlParameter("@Password", LoginUser.Password));

            SqlParameter outputParameter = new SqlParameter("@User_ID", SqlDbType.Int);

            int userID = SQLUtilities.RunStoredProcedure("Check_Login_Password", parameterList, outputParameter);

            Globals.UserID = userID;

            parameterList.Clear();
            parameterList.Add(new SqlParameter("@User_id", Globals.UserID));

            SqlParameter outputParameter2 = new SqlParameter("@Return", SqlDbType.Int);

            int admin = SQLUtilities.RunStoredProcedure("IsUserAdmin", parameterList, outputParameter2);

            Globals.IsAdmin = admin;

        }
    }
}
